package com.dc.diffutil

import android.content.Context
import android.os.Bundle
import androidx.recyclerview.widget.AsyncListDiffer

class AsyncDifferAdapter(context: Context): AsyncListDifferAdapter<UserBean>(context, R.layout.item_differ) {

    override fun createAsyncListDiffer(): AsyncListDiffer<UserBean> = AsyncListDiffer(this, AsyncDifferItemCallback())

    override fun convert(holder: ViewHolder, t: UserBean, position: Int) {
        // 对应2个参数的onBindViewHolder，刷新整个item
        holder.setText(R.id.tv_name, t.name)
        holder.setText(R.id.tv_job, t.job)
    }

    override fun convert(holder: ViewHolder, bundle: Bundle, position: Int) {
        // 对应3个参数的onBindViewHolder，item中哪个控件的数据有改动则刷新哪个控件
        val name = bundle.getString("name")
        name?.let {
            holder.setText(R.id.tv_name, it)
        }
        val job = bundle.getString("job")
        job?.let {
            holder.setText(R.id.tv_job, it)
        }
    }
}